package cn.song.rabbitmq;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 消息队列实体 - 用于传递数据
 *
 * @author SongRenShuo
 * @date 2024/01/22
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MqMessage<T>  implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * UUID -  用于唯一标识消息消息唯一标识
     */
    private String uuid;

    /**
     * 提示信息
     */
    private String message;
    /**
     * 数据
     */
    private T data;

    public MqMessage(MqMessage<T> mqMessage) {
        this.uuid = mqMessage.uuid;
        this.data = mqMessage.data;
        this.message = mqMessage.message;
    }

    public MqMessage(T data, String message) {
        this.data = data;
        this.message = message;
    }
    public MqMessage(String uuid, T data, String message) {
        this.uuid = uuid;
        this.data = data;
        this.message = message;
    }


    public void setMessage(String message) {
        if (this.message==null){
            this.message = message;
        }else {
            this.message = this.message + " " + message;
        }
    }

    public String getMessage() {
        return message == null ? "" : message;
    }
}
